Given an integer n, return a counter function. This counter function initially returns n and then returns 1 more than the previous value every subsequent time it is called (n, n + 1, n + 2, etc).
var createCounter = function(n) {
return function() {
return n++;
};
};
Example 1:
Input:
n = 10
["call","call","call"]
Output: [10,11,12]
Example 2:
Input:
n = -2
["call","call","call","call","call"]
Output: [-2,-1,0,1,2]
開始覺得這個 js 30天挑戰有點瞧不起人...
希望後面會變難,不然我花在文章排版的時間,還比較多==
var createCounter = function(n) {
return function() {
return n++;
};
};